package com.bky.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * Created by shipeilei on 2017/5/15.
 */
@Component
@Aspect
public class AspectService {
    /**
     * value：指定切入点表达式或命名切入点
     * pointcut：同样是指定切入点表达式或命名切入点，如果指定了将覆盖value属性指定的，pointcut具有高优先级
     * argNames：参数列表参数名
     * returning：返回值对应参数名
     * @param retVal
     */
    @AfterReturning(value = "execution(* com.bky.service.AddService.delete(..))", pointcut = "execution(* com.bky.service.AddService.delete(..))", argNames = "retVal", returning = "retVal")
    public void afterReturning(Object retVal){
        System.out.println("retVal=" + retVal);
    }
    @Before(value = "execution(* com.bky.service.AddService.getAll())")
    public void before(){
        System.out.println("执行before.....");
    }
    @After(value = "execution(* com.bky.service.AddService.getAll())")
    public void after(){
        System.out.println("执行after.....");
    }

    @Around(value = "execution(* com.bky.service.AddService.delete(..))")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("前Around.....");
        Object obj = pjp.proceed();
        System.out.println("后Around.....");
        return obj;
    }
    @AfterThrowing(value = "", pointcut = "execution(* com.bky.service.AddService.getAll())", argNames = "e", throwing = "e")
    public void afterThrowing(Exception e){
        System.out.println("异常后 e = " + e);
    }


}
